#!/usr/bin/env python

# !-*-coding:utf-8 -*-

# !@Time     : 2021/11/19 14:41

# !@Author   : xul

# !@File     : testTrain.py

import tf_utils
import test
# plt 用于显示图片
import matplotlib.pyplot as plt
# mpimg 用于读取图片
import matplotlib.image as mpimg
import numpy as np

X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = tf_utils.load_dataset()

# 每一列就是一个样本
X_train_flatten = X_train_orig.reshape(X_train_orig.shape[0], -1).T
X_test_flatten = X_test_orig.reshape(X_test_orig.shape[0], -1).T

# 归以化数据
X_train = X_train_flatten / 255
X_test = X_test_flatten / 255

# 转换为读热数据
Y_train = tf_utils.convert_to_one_hot(Y_train_orig, 6)
Y_test = tf_utils.convert_to_one_hot(Y_test_orig, 6)

parameters = test.model(X_train, Y_train, X_test, Y_test)

# 这是博主自己拍的图片
my_image1 = "5.png"
# 定义图片名称
fileName1 = "datasets/fingers/" + my_image1
# 图片地址
image1 = mpimg.imread(fileName1)
# 读取图片
plt.imshow(image1)
# 显示图片
my_image1 = image1.reshape(1, 64 * 64 * 3).T
# 重构图片
my_image_prediction = tf_utils.predict(my_image1, parameters)
# 开始预测
print("预测结果: y = " + str(np.squeeze(my_image_prediction)))
